#include "CDataCellId.h"

_LIT(KGsmModuleName, "phonetsy.tsy");

CDataCellId::CDataCellId()
{
}

CDataCellId* CDataCellId::NewL()
{
	CDataCellId * self = new (ELeave) CDataCellId ();
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop();
	return self;		
}

void CDataCellId::ConstructL()
{
	#ifndef __EMULATOR
		User::LeaveIfError(server.Connect() );
		User::LeaveIfError(server.LoadPhoneModule( KGsmModuleName ) );
		// initialize the phone object
		User::LeaveIfError(server.GetPhoneInfo( 0, iPhoneInfo ) );
		User::LeaveIfError(phone.Open( server, iPhoneInfo.iName ) );
	#endif
}

CDataCellId::~CDataCellId()
{
	#ifndef __EMULATOR
		phone.Close();
		server.UnloadPhoneModule( KGsmModuleName ); 
		server.Close();
	#endif
}

TInt CDataCellId::GetData(struct SGsmInfo& aGsmInfo)
{
	#ifndef __EMULATOR
		RMobilePhone::TMobilePhoneNetworkInfoV1 iRemotePartyInfo; 
		TPckg<RMobilePhone::TMobilePhoneNetworkInfoV1> des(iRemotePartyInfo);	
		phone.GetCurrentNetwork(iRequestStatus,des,iMPLocationAreaV1);
		User::WaitForRequest(iRequestStatus);
		aGsmInfo.CellID = iMPLocationAreaV1.iCellId;
		aGsmInfo.AreaID = iMPLocationAreaV1.iLocationAreaCode;
	#else
		aGsmInfo.CellID = 10;
		aGsmInfo.AreaID = 20;
	#endif
	 
	return KErrNone;	
}